package net.mcreator.magicio.procedures;

import net.minecraft.world.server.ServerWorld;
import net.minecraft.world.World;
import net.minecraft.world.IWorld;
import net.minecraft.util.text.StringTextComponent;
import net.minecraft.util.math.vector.Vector3d;
import net.minecraft.util.math.vector.Vector2f;
import net.minecraft.util.math.BlockPos;
import net.minecraft.item.ItemStack;
import net.minecraft.command.ICommandSource;
import net.minecraft.command.CommandSource;

import net.mcreator.magicio.MagicIoMod;

import java.util.Map;

public class GrowingProcedure {
	public static void executeProcedure(Map<String, Object> dependencies) {
		if (dependencies.get("x") == null) {
			if (!dependencies.containsKey("x"))
				MagicIoMod.LOGGER.warn("Failed to load dependency x for procedure Growing!");
			return;
		}
		if (dependencies.get("y") == null) {
			if (!dependencies.containsKey("y"))
				MagicIoMod.LOGGER.warn("Failed to load dependency y for procedure Growing!");
			return;
		}
		if (dependencies.get("z") == null) {
			if (!dependencies.containsKey("z"))
				MagicIoMod.LOGGER.warn("Failed to load dependency z for procedure Growing!");
			return;
		}
		if (dependencies.get("world") == null) {
			if (!dependencies.containsKey("world"))
				MagicIoMod.LOGGER.warn("Failed to load dependency world for procedure Growing!");
			return;
		}
		double x = dependencies.get("x") instanceof Integer ? (int) dependencies.get("x") : (double) dependencies.get("x");
		double y = dependencies.get("y") instanceof Integer ? (int) dependencies.get("y") : (double) dependencies.get("y");
		double z = dependencies.get("z") instanceof Integer ? (int) dependencies.get("z") : (double) dependencies.get("z");
		IWorld world = (IWorld) dependencies.get("world");
		if (world instanceof ServerWorld) {
			((World) world).getServer().getCommandManager().handleCommand(
					new CommandSource(ICommandSource.DUMMY, new Vector3d(x, y, z), Vector2f.ZERO, (ServerWorld) world, 4, "",
							new StringTextComponent(""), ((World) world).getServer(), null).withFeedbackDisabled(),
					(("summon magic_io:notetap ") + "" + ((x + 0.5)) + "" + (" ") + "" + (y) + "" + (" ") + "" + ((z + 0.5)) + "" + (" ") + ""
							+ ("{Glowing:true,Invulnerable:true,NoGravity:true,OnGround:false}")));
		}
		if (world instanceof ServerWorld) {
			((World) world).getServer().getCommandManager().handleCommand(
					new CommandSource(ICommandSource.DUMMY, new Vector3d((x + 0.5), y, (z + 0.5)), Vector2f.ZERO, (ServerWorld) world, 4, "",
							new StringTextComponent(""), ((World) world).getServer(), null).withFeedbackDisabled(),
					(("execute as @e[type=magic_io:notetap,distance=..0,limit=1] run team join") + ""
							+ ((("" + (/* @ItemStack */(new ItemStack((world.getBlockState(new BlockPos((int) x, (int) y, (int) z))).getBlock()))))
									.replace("1 ", " ")))));
		}
	}
}
